<!DOCTYPE>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>一码通网上商城</title>
	<link rel="stylesheet" href="../css/login.css">
	<link rel="stylesheet" href="../css/reset.css">
	<script src="http://beian.80wlkj.com/data/resource/js/jquery.js"></script>
	<script type="text/javascript" src="../js/storage.js"></script>
</head>
<body>
	<div class="login">
		<div class="logo">
			<img src="../imgs/index/logo.png" alt="">
			<p>欢迎登录</p>
		</div>
		<div class="banner">
			<div class="formWrap">
				<div class="form">
		    	<div class="formTitle">
		    		账户登录
		    	</div>
			    <div class="formBar">
				    <p>用户名</p>
				    <input id="userName" type="text" placeholder="3-15位字符，可由英文、数字组成">
			    </div>
			    <div class="formBar">
				    <p>密码</p>
				    <input id="userPsd" type="text" placeholder="6-16位字符，可由英文、数字组成">
			    </div>
			    <div class="formBar">
				    <button id="submitBtn" class="submitBtn">登录</button>
			    </div>
		    </div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	$(function(){
		var submitBtn = $('#submitBtn');
		submitBtn.click(function(){
		 _login();
		});
		$(document).keyup(function(event){
        if(event.keyCode ==13){
         submitBtn.trigger("click");
        }
    });
	function _login(){
		    var userName = $('#userName');
		    var userPsd  = $('#userPsd');
			if (!userName.val()){
				alert('用户名不能为空');
				return false;
			}else if(!userPsd.val()){
				alert('密码不能为空');
				return false;
			}

			$.ajax({
				url:'http://192.168.0.120:8080/ymshoping/login?username='+userName.val()+'&password=' + userPsd.val(),
				dataType:'jsonp',
				jsonp:'callback',//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(默认为:callback)
                jsonpCallback:"success_jsonpCallback",//自定义的jsonp回调函数名称，默认为jQuery自动生成的随机函数名
				contentType: 'application/json; charset=utf-8',
				success:function(res){
					console.log(res);
					if (res.code == 0) {
						var tokenJson = {name:'token',value:res.token};
						var usernameJson = {name:'username',value:res.username};
						storage.setStorage(tokenJson);
						storage.setStorage(usernameJson);
						console.log(storage.getStorage('token'));
						window.location.href = "./index.html";
						window.close();
					}
				},
				error:function(res){
					console.log(res.responseText);
				}
			});
	}
})
	
</script>
</html>